/*
ID: icerupt1
PROG: transform
LANG: C++11
*/
#include <fstream>
#include <functional>
#include <array>
#include <sstream>
#include <string>

namespace
{
	int n;
	std::string src, dst;

	using transform = std::function<int(int, int)>;
	auto identity = [] (int y, int x) { return y*n+x; };
	std::array<transform, 8> transforms {{
		[] (int y, int x) { return identity(  x  , n-y-1); },
		[] (int y, int x) { return identity(n-y-1, n-x-1); },
		[] (int y, int x) { return identity(  x  , n-y-1); },
		[] (int y, int x) { return identity(  y  , n-x-1); },
		[] (int y, int x) { return identity(n-x-1, n-y-1); },
		                           identity                 ,
		[] (int y, int x) { return identity(n-y-1,   x  ); },
		[] (int y, int x) { return identity(  x  ,   y  ); },
	}};

	auto equal_tranformed(transform const& t)
	{
		for (auto y=0; y<n; y++)
			for (auto x=0; x<n; x++) {
				if (dst[t(y, x)] != src[identity(y, x)])
					return false;
			}
		return true;
	}

	int select()
	{
		for (auto i=0u; i<transforms.size(); i++) {
			if (equal_tranformed(transforms[i]))
				return (i < 6 ? i : 4);
		}
		return 6;
	}

	auto read_matrix(std::istream & is, int n)
	{
		std::ostringstream ss;
		while (n--) {
			std::string line;
			is >> line;
			ss << line;
		}
		return ss.str();
	}
}

int main()
{
	std::ifstream fin {"transform.in" };
	std::ofstream fout{"transform.out"};
	fin >> n;
	src = read_matrix(fin, n);
	dst = read_matrix(fin, n);
	fout << select() + 1 << "\n";
}

